package com.vken.blog.util;

import java.util.List;

public class Pagination {
	private int pageSize = 20;
	private int pageNumber = 1;
	private int maxElements;
	private List list;
	private int offset;

	public Pagination() {

	}

	public Pagination(int maxElements) {
		this.maxElements = maxElements;
	}

	public Pagination(int pageSize, int pageNumber, int maxElements) {
		this.pageSize = pageSize;
		this.maxElements = maxElements;
		this.pageNumber = pageNumber;
	}

	public int getPageNumber() {
		return pageNumber;
	}

	public void setPageNumber(int pageNumber) {
		int total = (int) Math.ceil(maxElements / pageSize);
		if (pageNumber > total) {
			this.pageNumber = total;
		} else if (pageNumber <= 1) {
			pageNumber = 1;
		}else{
			this.pageNumber = pageNumber;
		}
	}

	public void setMaxElments(int maxElements) {
		this.maxElements = maxElements;
	}

	public int getMaxElements() {
		return maxElements;
	}

	public int getOffset() {
		return offset;
	}

	public void setOffset(int offset) {
		if (offset <= 0) {
			this.offset = 0;
		} else if (offset > maxElements) {
			this.offset = maxElements-1;
		} else {
			this.offset = offset;
		}
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setList(List list) {
		this.list = list;
	}

	public List getList() {
		return list;
	}
}
